package com.yxkj.syh.app.huarong.activities.item_select;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.syh.app.basic.base.view_model.BaseViewModel;
import com.syh.app.basic.utils.Tooast;
import com.syh.app.basic.utils.net.ApiObserver;
import com.trello.rxlifecycle2.android.ActivityEvent;
import com.yxkj.syh.app.huarong.bean.CommonAddressResponse;
import com.yxkj.syh.app.huarong.bean.LinkListResponse;
import com.yxkj.syh.app.huarong.bean.PagesRequest;
import com.yxkj.syh.app.huarong.data_center.model.CommonModel;

import java.util.ArrayList;
import java.util.List;

/**
 * 创建者：SYH
 * 时间：2020/6/11 9:17
 * 编辑者：SYH、
 * 标签：
 * 补充说明：
 */
public class AddressSelectVM extends BaseViewModel<ActivityEvent> {

    public AddressSelectVM(@NonNull Application application) {
        super(application);
    }


    public MutableLiveData<Object> mldShowText = new MutableLiveData<>();


    /**
     * 常用地址列表
     * @param type 0 纸厂列表  1默认 常用列表
     */
    public void commonAddress(int type) {
        PagesRequest request = new PagesRequest();
        request.setPageIndex(1);
        request.setPageSize(10000);
        List<PagesRequest.SqlParam> sqlParams = new ArrayList<>();
        PagesRequest.SqlParam sqlParam = new PagesRequest.SqlParam();
        sqlParam.setKey("o.locationType");
        sqlParam.setOper("=");
        sqlParam.setValue(type);
        sqlParams.add(sqlParam);
        request.setQueryList(sqlParams);
        CommonModel.getCommonModel().getCommonAddress(request, mLifecycleProvider.bindToLifecycle(), new ApiObserver<CommonAddressResponse>() {
            @Override
            public void onSuccess(CommonAddressResponse response) {
                mldShowText.setValue(response.getData().getRecords());
            }

            @Override
            public void onFailed(int code, String msg) {
                Tooast.warning(msg);
            }
        });
    }

}
